<?php
set_time_limit(0);
include_once '../include/lxbase.class.php';
include_once '../lib/nusoaplib/client.php';
$data = json_decode($_POST["data"],true);
//检测参数是否齐全
if(empty($data)){
	die(json_encode(array("error"=>1002,"errmsg"=>"missing some parameter")));
}
//if(empty($data["userid"])){
//	die(json_encode(array("error"=>1001,"errmsg"=>"missing user identifying")));
//}
if(empty($data["pid"])){
	die(json_encode(array("error"=>1008,"errmsg"=>"Missing platform identifying")));
}
if(empty($data["msg"]) || empty($data["mobile"])){
	die(json_encode(array("error"=>1002,"errmsg"=>"missing some parameter")));
}

//网关
$gwUrl = 'http://sdkhttp.eucp.b2m.cn/sdk/SDKService?wsdl';
//序列号
$serialNumber = '3SDK-EMY-0130-REXSL';
//密码
$password = '395297';
//KEY
$sessionKey = 242349;

/**
$connectTimeOut = 5;
$readTimeOut = 20;
$proxyhost = false;
$proxyport = false;
$proxyusername = false;
$proxypassword = false;
*/	
//创建对象
$client = new Client($gwUrl,$serialNumber,$password,$sessionKey);
//指定字符集 
$client->setOutgoingEncoding("UTF-8");
/*if(empty($_SESSION["mobliekey"])){
	if($client->login()==0){
		$_SESSION["mobliekey"] = $sessionKey;
	}else{
		die(json_encode(array("error"=>1007,"errmsg"=>"Paramet error")));
	}
}*/
//发送短信
$statusCode = $client->sendSMS($data["mobile"],'【企悦】'.$data["msg"]);
if($statusCode==0){
	die(json_encode(array("error"=>1000,"errmsg"=>"success")));
}else{
	$errarr=array(17=>"发送信息失败",18=>"发送定时信息失败",303=>"客户端网络故障",305=>"服务器端返回错误，错误的返回值",307=>"目标电话号码不符合规则，电话号码必须是以0、1开头",997=>"平台返回找不到超时的短信，该信息是否成功无法确定",998=>"由于客户端网络问题导致信息发送超时，该信息是否成功下发无法确定");
	die(json_encode(array("error"=>1003,"errmsg"=>$errarr[$statusCode])));
}